package pl.edu.agh.mobsys.activities.soapactivities;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Packet;

import pl.edu.agh.mobsys.R;
import pl.edu.agh.mobsys.XmppApplication;
import pl.edu.agh.mobsys.data.ConnectionConfig;
import pl.edu.agh.mobsys.data.SoapXmppMessage;
import pl.edu.agh.mobsys.soap.JobData;
import pl.edu.agh.mobsys.soap.SOAPBuilder;
import pl.edu.agh.mobsys.soap.JobData.JobState;
import pl.edu.agh.mobsys.utils.BB;
import pl.edu.agh.mobsys.utils.Constants;
import pl.edu.agh.mobsys.utils.SmoaJobsArrayAdapter;
import pl.edu.agh.mobsys.utils.SmoaParser;
import pl.edu.agh.mobsys.utils.Constants.SmoaAgentType;
import pl.edu.agh.mobsys.utils.SmoaParser.MessageType;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnKeyListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

public class Jobs extends ListActivity implements View.OnClickListener,
		OnKeyListener {

	private static final String TAG = "Jobs";

	private static final int RESUBSCRIBE_DIALOG_ID = 0;

	private SmoaJobsArrayAdapter jobsAdapter;

	private TextView empty;

	private int activatedJob = -1;

	private XmppApplication app;

	private ArrayList<JobData> jobs;

	private String alias;

	private org.jivesoftware.smack.Chat notifierChat;
	private org.jivesoftware.smack.Chat jobReceiverChat;
	private String notifierAgentName;
	private String jobReceiverAgentName;

	private String meServer, meResource, meName;

	private boolean subscribed;
	private String subscriptionID;

	private final String CONTEXT_GET_JOB_STATUS = "Get job status";
	private final String CONTEXT_CANCEL_JOB = "Cancel job";
	private final String CONTEXT_REMOVE_FROM_LIST = "Remove from list";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.jobs_list);
		Log.d(TAG, "Executing onCreate");

		this.empty = (TextView) findViewById(R.id.jobsListEmpty);

		// set list properties
		final ListView listView = getListView();
		listView.setItemsCanFocus(false);
		listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		listView.setEmptyView(this.empty);
		registerForContextMenu(listView);

		alias = getIntent().getStringExtra(Constants.ACTIVATED_CONTACT);

		ConnectionConfig cc = ConnectionConfig
				.readFromSharedPreferences(getSharedPreferences(
						Constants.SHARED_PREFS_KEY_SERVER_CONFIG,
						Context.MODE_WORLD_READABLE));
		meServer = cc.host;
		meResource = cc.resource;
		meName = cc.username;

		// prefs = getSharedPreferences(Constants.SHARED_PREFS_KEY_CONTACTS,
		// Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

		app = (XmppApplication) getApplication();
		jobs = new ArrayList<JobData>();
		jobsAdapter = new SmoaJobsArrayAdapter(this, jobs);
		listView.setAdapter(jobsAdapter);

		Log.d(TAG, "Changing subscribed to false");
		subscribed = false;
		Log.d(TAG, "Changed subscribed to: " + subscribed);

		if (app.getJobsPacketListener() == null) {
			Log.d(TAG, "Creating jobsPacketListener");
			app.setJobsPacketListener(new PacketListener() {
				public void processPacket(final Packet packet) {
					processSmoaPacket(packet);
				}
			});
			app.getXMPPConnection().addPacketListener(
					app.getJobsPacketListener(),
					SmoaParser.getSmoaPacketFilter());
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		updateJobs();
		jobsAdapter.notifyDataSetChanged();
		Log.d(TAG, "Jobs list size: " + app.getJobs(alias).size());
		notifierChat = ((XmppApplication) getApplication()).getChat(alias,
				SmoaAgentType.NOTIFIER);

		if (notifierChat != null) {
			// for (MessageListener ml : notifierChat.getListeners()) {
			// notifierChat.removeMessageListener(ml);
			// }
			// notifierChat.addMessageListener(listener);
			// app.getXMPPConnection().addPacketListener(packetListener,
			// SmoaParser.getSmoaPacketFilter());
			//
			// Log.d(TAG, "Listener added to: " +
			// notifierChat.getParticipant());
		} else {
			Toast.makeText(getApplicationContext(),
					"Failed to create chat for " + alias + "'s notifier",
					Toast.LENGTH_SHORT).show();
		}
		jobReceiverChat = ((XmppApplication) getApplication()).getChat(alias,
				SmoaAgentType.JOB_RECEIVER);
		if (jobReceiverChat == null) {
			Toast.makeText(getApplicationContext(),
					"Failed to create chat for " + alias + "'s job receiver",
					Toast.LENGTH_SHORT).show();
		}
		notifierAgentName = notifierChat.getParticipant().substring(0,
				notifierChat.getParticipant().indexOf('@'));
		jobReceiverAgentName = jobReceiverChat.getParticipant().substring(0,
				jobReceiverChat.getParticipant().indexOf('@'));
		Log.d(TAG, jobReceiverAgentName + " <- ["
				+ jobReceiverChat.getParticipant() + "]");
		// Log.d("TAG", "contact data of " + alias + ": " + (String)
		// getSharedPreferences(Constants.SHARED_PREFS_KEY_SERVER_CONFIG,
		// Context.MODE_WORLD_READABLE +
		// Context.MODE_WORLD_WRITEABLE).getAll().get(alias));
		// smoaContact = (SmoaContact) ContactFactory.buildContact(alias,
		// (String)
		// getSharedPreferences(Constants.SHARED_PREFS_KEY_SERVER_CONFIG,
		// Context.MODE_WORLD_READABLE +
		// Context.MODE_WORLD_WRITEABLE).getAll().get(alias));
	}

	// @Override
	// protected void onPause() {
	// super.onPause();
	// app.getXMPPConnection().removePacketListener(packetListener);
	// }
	@Override
	protected void onDestroy() {
		super.onStop();
		app.getXMPPConnection().removePacketListener(
				app.getJobsPacketListener());
		app.setJobsPacketListener(null);
	}

	private void updateJobs() {
		JobData[] jobsArray = new JobData[app.getJobs(alias).size()];
		int i = 0;
		Iterator it = app.getJobs(alias).entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry pair = (Map.Entry) it.next();
			System.out.println(pair.getKey() + " = " + pair.getValue());
			jobsArray[i++] = (JobData) pair.getValue();
		}
		// ////////////////////////////////////////////////////
		// jobs.clear();
		// JobData jobData = new JobData("Job 1","/bin/sleep","15");
		// jobData.setJobState(JobState.FINISHED);
		// jobs.add(jobData);
		// jobData = new JobData("Job 2","/bin/sleep","15");
		// jobData.setJobState(JobState.FINISHED);
		// jobs.add(jobData);
		// jobData = new JobData("Job 3","/bin/sleep","15");
		// jobData.setJobState(JobState.FINISHED);
		// jobs.add(jobData);
		// jobData = new JobData("Job 4","/bin/sleep","15");
		// jobData.setJobState(JobState.EXECUTING);
		// jobs.add(jobData);
		// jobData = new JobData("Job 5","/bin/sleep","15");
		// jobData.setJobState(JobState.QUEUED);
		// jobs.add(jobData);
		// jobData = new JobData("Job 6","/bin/sleep","15");
		// jobData.setJobState(JobState.QUEUED);
		// jobs.add(jobData);
		// ////////////////////////////////////////////////////
		Arrays.sort(jobsArray);
		jobs.clear();
		for (int j = 0; j < jobsArray.length; ++j) {
			jobs.add(jobsArray[j]);
		}
	}

	private Set<BB> bbs;

	private void createBottomButtons() {
		if (bbs == null) {
			bbs = new HashSet<BB>();
		} else {
			bbs.clear();
		}

		// subskrypcja
		if (subscribed == false) {
			Log.d(TAG, "subscribed: false");
			bbs.add(new BB(R.string.soap_subscribe, 0,
					R.drawable.subscribe_icon, null));
		} else {
			Log.d(TAG, "subscribed: true");
			bbs.add(new BB(R.string.soap_renew_subscription, 0,
					R.drawable.subscribe_icon, null));
		}

		// dodanie zadania
		bbs.add(new BB(R.string.soap_add_job, 1, R.drawable.add_job_icon,
				new Intent(Constants.SOAP_ADD_JOB)));

		// // sprawdzenie stanu zadania
		// bbs.add(new BB(R.string.soap_get_job_status, 1,
		// R.drawable.get_job_status_icon, new Intent(
		// Constants.SOAP_GET_JOB_STATUS)));

		// // wywalenie zadania
		// bbs.add(new BB(R.string.soap_delete_job, 2,
		// R.drawable.recycle_bin_icon, null));

		// cofni�cie subskrybcji
		bbs.add(new BB(R.string.soap_unsubscribe, 4,
				R.drawable.unsubscribe_icon, null));

		// // separator
		// bbs.add(new BB(R.string.space, 5, -1, null));
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		super.onPrepareOptionsMenu(menu);
		menu.removeGroup(0);
		createBottomButtons();
		MenuItem menuItem;
		for (BB bb : bbs) {
			menuItem = menu.add(0, bb.id, bb.id, bb.labelId);
			if (bb.icon != -1) {
				menuItem.setIcon(bb.icon);
			}
		}
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		for (BB bb : bbs) {
			// Log.d(TAG, "Current menu option: " + bb.id);
			if (bb.id == item.getItemId()) {
				if (bb.labelId == R.string.soap_subscribe) {
					Log.d(TAG, "Opening soap_subscribe");
					subscribe();
				} else if (bb.labelId == R.string.soap_renew_subscription) {
					resubscribe();
				} else if (subscribed == false) {
					Toast.makeText(getApplicationContext(),
							R.string.soap_subscribe_first, Toast.LENGTH_SHORT)
							.show();
				}
				// dodanie zadania
				else if (bb.labelId == R.string.soap_add_job) {
					Log.d(TAG, "Opening: [" + Integer.toString(bb.id) + "]");
					bb.intent.putExtra(Constants.ACTIVATED_CONTACT, alias);
					bb.intent.putExtra(SmoaAgentType.NOTIFIER.toString(),
							notifierAgentName);
					bb.intent.putExtra(SmoaAgentType.JOB_RECEIVER.toString(),
							jobReceiverAgentName);
					startActivity(bb.intent);
					// }
					// // usuni�cie zadania
					// else if (bb.labelId == R.string.soap_delete_job) {
					// if (activatedJob < 0) {
					// Toast.makeText(getApplicationContext(),
					// R.string.soap_no_selection, Toast.LENGTH_SHORT)
					// .show();
					// } else {
					// showDeleteConfirmationDialog();
					// }
				} else if (bb.labelId == R.string.soap_unsubscribe) {
					Log.d(TAG, "Opening soap_unsubscribe");
					unsubscribe();
				} else {
					Log.d(TAG, "Opening: [" + Integer.toString(bb.id) + "]");
					/*
					 * bb.intent .putExtra( Constants.ACTIVATED_CONTACT,
					 * activatedContact >= 0 && activatedContact < contacts
					 * .size() ? contacts .get(activatedContact).alias : null);
					 * startActivity(bb.intent); // TODO sprawdzić
					 */
				}
				return true;
			}
		}
		return false; // super.onMenuItemSelected(featureId, item);
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
		menu.add(CONTEXT_GET_JOB_STATUS);
		if (jobs.get(info.position).getJobState() != JobState.FINISHED
				&& jobs.get(info.position).getJobState() != JobState.CANCELLED) {
			menu.add(CONTEXT_CANCEL_JOB);
		} else {
			menu.add(CONTEXT_REMOVE_FROM_LIST);
		}
		menu.setHeaderTitle(jobs.get(info.position).getName());
	}

	@Override
	public boolean onContextItemSelected(MenuItem item) {
		AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item
				.getMenuInfo();

		Log.d(TAG, "onContextItemSelected!");

		activatedJob = info.position;
		Log.d(TAG, "Selected position: " + activatedJob);

		if (CONTEXT_CANCEL_JOB.equals(item.getTitle())) {
			showDeleteConfirmationDialog(jobs.get(activatedJob));
		} else if (CONTEXT_GET_JOB_STATUS.equals(item.getTitle())) {
			getJobStatus(jobs.get(activatedJob));
		} else if (CONTEXT_REMOVE_FROM_LIST.equals(item.getTitle())) {
			app.getJobs(alias).remove(jobs.get(activatedJob).getAid());
			updateJobs();
			jobsAdapter.notifyDataSetChanged();
		}
		return false;
	}

	private void getJobStatus(JobData jobData) {
		String getJobStatusMessage = SOAPBuilder
				.getAskStatusMessage(Constants.SOAP_ID_PREFIX
						+ jobData.getAid());
		sendMessage(getJobStatusMessage, Constants.SmoaAgentType.JOB_RECEIVER);
	}

	private void subscribe() {
		String subscribeMessage = SOAPBuilder.getSubscribeMessage(meName,
				meServer, meResource);
		sendMessage(subscribeMessage, Constants.SmoaAgentType.NOTIFIER);

		// String subMes =
		// "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://www.w3.org/2003/05/soap-envelope'>    <SOAP-ENV:Header>        <wsa5:MessageID xmlns:wsa5='http://www.w3.org/2005/08/addressing'>uuid:7</wsa5:MessageID>        <wsa5:To xmlns:wsa5='http://www.w3.org/2005/08/addressing'            SOAP-ENV:mustUnderstand='1'>xmpp:smoatest1@grass2.man.poznan.pl/JabberMix</wsa5:To>        <wsa5:Action xmlns:wsa5='http://www.w3.org/2005/08/addressing'            SOAP-ENV:mustUnderstand='1'>http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest        </wsa5:Action>    </SOAP-ENV:Header>    <SOAP-ENV:Body>        <wsnt:Subscribe xmlns:wsnt='http://docs.oasis-open.org/wsn/b-2'>            <wsnt:ConsumerReference>                <wsa5:Address xmlns:wsa5='http://www.w3.org/2005/08/addressing'>xmpp:smoatest1@grass2.man.poznan.pl/JabberMix</wsa5:Address>            </wsnt:ConsumerReference>            <wsnt:Filter>                <wsnt:TopicExpression                    xmlns:tns='http://schemas.smoa-project.com/comp/2009/01/notification/topic'                    Dialect='http://docs.oasis-open.org/wsn/t-1/TopicExpression/Full'>tns://*</wsnt:TopicExpression>            </wsnt:Filter>        </wsnt:Subscribe>    </SOAP-ENV:Body></SOAP-ENV:Envelope>";
		// sendMessage(subMes, Constants.SmoaAgentType.NOTIFIER);
		// Toast.makeText(getApplicationContext(), R.string.soap_subscribed,
		// Toast.LENGTH_SHORT).show();
	}

	private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
		public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
			try {
				String resubscribeMessage = SOAPBuilder
						.getRenewSubscribeMessage(meName, meServer, meResource,
								subscriptionID, formatSubscriptionDate(
										hourOfDay, minute));
				Log
						.d(TAG, "Sending resubscribe message: "
								+ resubscribeMessage);
				sendMessage(resubscribeMessage,
						Constants.SmoaAgentType.NOTIFIER);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	};

	private void resubscribe() {
		showDialog(RESUBSCRIBE_DIALOG_ID);
	}

	private Calendar c;
	private final SimpleDateFormat dateFormat = new SimpleDateFormat(
			"yyyy-MM-ddHH:mm:ssZ");

	protected String formatSubscriptionDate(int hourOfDay, int minute) {
		c = Calendar.getInstance();
		c.add(Calendar.HOUR, hourOfDay);
		c.add(Calendar.MINUTE, minute);
		String s = dateFormat.format(c.getTime());
		return s.substring(0, 10) + "T" + s.substring(10, 21) + ":"
				+ s.substring(21);
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		if (id != RESUBSCRIBE_DIALOG_ID) {
			return null;
		}
		TimePickerDialog tpd = new TimePickerDialog(this, mTimeSetListener, 1,
				0, true) {
					@Override
					public void onTimeChanged(TimePicker view, int hourOfDay,
							int minute) {
						super.onTimeChanged(view, hourOfDay, minute);
						setTitle(hourOfDay + "h " + minute + "m");
					}
		};
		tpd.setTitle("Termination period");
		return tpd;
	}

	private void unsubscribe() {
		String unsubscribeMessage = SOAPBuilder.getDeleteSubscribeMessage(
				meName, meServer, meResource, subscriptionID);
		sendMessage(unsubscribeMessage, Constants.SmoaAgentType.NOTIFIER);
	}

	private void displayPopup(String title, String[] items) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle(title);
		builder.show();
	}

	public void onClick(View v) {

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		activatedJob = position;
		super.onListItemClick(l, v, position, id);
	}

	private void showDeleteConfirmationDialog(final JobData jobData) {
		// prepare the alert box
		AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
		alertbox.setMessage(getResources().getString(
				R.string.soap_confirm_cancel));

		String aid = jobData.getAid();
		Log.d(TAG, "jobData.getAid(): " + aid);

		alertbox.setPositiveButton(getResources().getString(
				R.string.con_confirm_yes),
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface arg0, int arg1) {
						String cancelJobMessage = SOAPBuilder
								.getDeleteJobMessage(meName, meServer,
										meResource, Constants.SOAP_ID_PREFIX
												+ jobData.getAid());
						Log.d(TAG, "Cancel job message: " + cancelJobMessage);
						sendMessage(cancelJobMessage,
								SmoaAgentType.JOB_RECEIVER);
					}
				});

		alertbox.setNegativeButton(getResources().getString(
				R.string.con_confirm_no),
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface arg0, int arg1) {
						; // nic się nie dzieje
					}
				});

		alertbox.show();
	}

	public boolean onKey(View v, int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		return false;
	}

	protected void sendMessage(final String message,
			Constants.SmoaAgentType agentType) {
		if (message == null || "".equals(message)) {
			return;
		}

		org.jivesoftware.smack.Chat chat = (agentType == Constants.SmoaAgentType.NOTIFIER) ? notifierChat
				: jobReceiverChat;

		try {
			chat.sendMessage(new SoapXmppMessage(message));
			Log.i(TAG, "Message to " + chat.getParticipant() + ": " + message);
		} catch (XMPPException e) {
			Toast.makeText(getApplicationContext(),
					R.string.chat_failed_to_send + " : " + e.getMessage(),
					Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		} /*
		 * catch (Exception e) { e.printStackTrace(); }
		 */finally {
			// newMessage.setText("");
		}

	}

	private void processSmoaPacket(final Packet packet) {
		final SmoaParser.ParsedMessage parsedMessage = SmoaParser.parseMessage(
				packet, notifierAgentName, jobReceiverAgentName);

		Log.d(TAG, parsedMessage.messageType + "  id: [" + parsedMessage.id
				+ "] info: [" + parsedMessage.info + "]\n" + packet.toXML());

		if (parsedMessage.messageType == MessageType.SubscribeConfirmation) {
			this.subscribed = true;
			subscriptionID = parsedMessage.id;
			runOnUiThread(new Runnable() {
				public void run() {
					Toast.makeText(
							getApplicationContext(),
							getResources().getString(R.string.soap_subscribed)
									+ " (id: " + parsedMessage.id + ")",
							Toast.LENGTH_SHORT).show();
					Log.d(TAG, "Subscribtion ID: " + subscriptionID
							+ " subscribed: " + subscribed);
				}
			});
		} else if (parsedMessage.messageType == MessageType.ResubscribeConfirmation) {
			if (parsedMessage.id.equals(subscriptionID) == false) {
				Log.e(TAG, "Subscription IDs not matching: " + subscriptionID
						+ " " + parsedMessage.id);
			} else {
				subscribed = true;
				runOnUiThread(new Runnable() {
					public void run() {
						Toast.makeText(
								getApplicationContext(),
								getResources().getString(
										R.string.soap_resubscribed)
										+ " (id: " + parsedMessage.id + ")",
								Toast.LENGTH_SHORT).show();
						Log
								.d(TAG, "Resubscribed. Subscribtion ID: "
										+ subscriptionID + " subscribed: "
										+ subscribed);
					}
				});
			}
		} else if (parsedMessage.messageType == MessageType.UnsubscribeConfirmation) {
			if (parsedMessage.id.equals(subscriptionID) == false) {
				Log.e(TAG, "Subscription IDs not matching: " + subscriptionID
						+ " " + parsedMessage.id);
			} else {
				subscribed = false;
				runOnUiThread(new Runnable() {
					public void run() {
						Toast.makeText(getApplicationContext(),
								R.string.soap_unsubscribed, Toast.LENGTH_SHORT);
						Log.d(TAG, "Unsubscribed");
					}
				});
			}
		} else if (parsedMessage.messageType == MessageType.JobStatusUpdate) {
			String state = parsedMessage.info;
			JobData jobData = null;
			for (int i = 0; i < jobs.size(); ++i) {
				if (jobs.get(i).getAid().equals(parsedMessage.id)) {
					jobData = jobs.get(i);
					break;
				}
			}
			if (state.equals("Queued") || state.equals("Pending")) {
				jobData.setJobState(JobState.QUEUED);
			} else if (state.equals("Executing") || state.equals("Running")) {
				jobData.setJobState(JobState.EXECUTING);
			} else if (state.equals("Paused")) {
				jobData.setJobState(JobState.PAUSED);
			} else if (state.equals("Finished")) {
				jobData.setJobState(JobState.FINISHED);
			}
			runOnUiThread(new Runnable() {
				public void run() {
					jobsAdapter.notifyDataSetChanged();
				}
			});
		} else if (parsedMessage.messageType == MessageType.CancelJobConfirmation) {
			JobData jobData = null;
			for (int i = 0; i < jobs.size(); ++i) {
				if (jobs.get(i).getAid().equals(parsedMessage.id)) {
					jobData = jobs.get(i);
					break;
				}
			}
			jobData.setJobState(JobState.CANCELLED);
			runOnUiThread(new Runnable() {
				public void run() {
					jobsAdapter.notifyDataSetChanged();
				}
			});
		} else {
			runOnUiThread(new Runnable() {
				public void run() {
					Toast.makeText(getApplicationContext(),
							"Other kind of message", Toast.LENGTH_SHORT);
				}
			});
		}
	}

}
